import { Response } from "express";

interface ApiResponse<T = any> {
  code: number;
  success: boolean;
  message: string;
  data?: T;
}

export const success = <T = any>(
  res: Response,
  data?: T,
  message: string = "ok"
) => {
  const result: ApiResponse<T> = {
    code: 200,
    success: true,
    message,
    data,
  };
  res.status(200).json(result);
};

export const fail = <T = any>(
  res: Response,
  code: number,
  message: string,
  errors?: T
) => {
  const result: ApiResponse<T> = {
    code,
    success: false,
    message,
    data: errors,
  };
  res.status(code).json(result);
};
